package com.tuyue.police.controller.vip;

import com.tuyue.police.biz.ISmsBiz;
import com.tuyue.police.enums.ResultEnum;
import com.tuyue.police.exception.MyException;
import com.tuyue.police.util.Result;
import com.tuyue.police.util.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: 王金海
 * @Description:
 * @Date: Created by Administrator on 2018/3/19.
 * @Modified By:
 */
@RestController
@RequestMapping("vip/sms")
public class SmsController {
    @Autowired
    private ISmsBiz smsBiz;


    @GetMapping("send/{phone}")
    public Result send(@PathVariable String phone){
        if (phone.length()!=11) {
           throw new MyException(ResultEnum.SMS_TELERROR);
        }
        boolean b = smsBiz.sendSms( phone);
        if(b){
            return ResultUtil.success();
        }
        return ResultUtil.error(ResultEnum.SMS_SENDERROR);
    }


    @GetMapping("verify/{phone}")
    public Result verify(@PathVariable String phone,String code){
        boolean b = smsBiz.verifySms( phone,code);
        if(b){
            return ResultUtil.success();
        }
        return ResultUtil.error(ResultEnum.SMS_CODEERROR);
    }
}
